<?php

namespace App\Models\System;

use App\Models\BaseModel;
use Illuminate\Support\Facades\Storage;

class Attachment extends BaseModel
{
    protected $fillable = [
        'admin_id',
        'user_id',
        'filename',
        'url',
        'url_md5',
        'filesize',
        'extparam',
        'fileinfo',
        'mimetype',
        'sha1',
    ];

    protected static function booted(): void
    {
        static::deleted(function (self $row) {
            Storage::disk('public')->delete($row->url);
        });
    }
}
